<?php


/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Badge
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
?>
<script type="text/javascript">

var currentOrder = '<?php echo $this->order ?>';
var currentOrderDirection = '<?php echo $this->order_direction ?>';
var changeOrder = function(order, default_direction){
  // Just change direction
  if( order == currentOrder ) {
    $('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
  } else {
    $('order').value = order;
    $('order_direction').value = default_direction;
  }
  $('filter_form').submit();
}


  en4.core.runonce.add(function(){$$('th.admin_table_short input[type=checkbox]').addEvent('click', function(){ $$('input[type=checkbox]').set('checked', $(this).get('checked', false)); })});

  var delectSelected =function(){
    var checkboxes = $$('input[type=checkbox]');
    var selecteditems = [];

    checkboxes.each(function(item, index){
      var checked = item.get('checked', false);
      var value = item.get('value', false);
      if (checked == true && value != 'on'){
        selecteditems.push(value);
      }
    });

    $('ids').value = selecteditems;
    $('delete_selected').submit();
  }

</script>

<h2><?php echo $this->translate("Badges Plugin") ?></h2>

<?php if( count($this->navigation) ): ?>
  <div class='tabs'>
    <?php
      // Render the menu
      //->setUlClass()
      echo $this->navigation()->menu()->setContainer($this->navigation)->render()
    ?>
  </div>
<?php endif; ?>

<p>
  <?php echo $this->translate("This page allows to you manage member's requests to have awarded badges.") ?>
</p>
<br />

<div class='admin_search'>
  <?php echo $this->formFilter->render($this) ?>
</div>

<br />



<?php if( count($this->paginator) ): ?>

<div class='admin_results'>
  <div>
    <?php $badgeCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s request found", "%s requests found", $badgeCount), ($badgeCount)) ?>
  </div>
  <div>
    <?php // echo $this->paginationControl($this->paginator, null, null, array('params'=>$this->params)); ?>
    
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>  
    
  </div>
</div>
<br />

<table class='admin_table'>
  <thead>
    <tr>
      <th class='admin_table_short'><a href="javascript:void(0);" onclick="javascript:changeOrder('request_id', 'ASC');">ID</a></th>
      <th><?php echo $this->translate('Badge');?></th>
      <th><?php echo $this->translate('Member');?></th>
      <!-- <th><?php echo $this->translate('Message');?></th>  -->
      <th><?php echo $this->translate('Submitted');?></th>
      <th><?php echo $this->translate('Status'); ?></th>
      <th><?php echo $this->translate("Options") ?></th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($this->paginator as $request): $badge = $request->getBadge(); ?>
      <tr>
        <td><?php echo $request->getIdentity(); ?></td>
        <td><?php echo $badge->__toString(); ?></td>  
        <td><?php echo $request->getUser()->__toString(); ?></td>  
        <?php /*<td>
          <?php echo $this->viewMore($request->getDescription());?>
        </td>
        */ ?>
        <td>
          <?php echo $this->locale()->toDateTime($request->creation_date) ?>
        </td>
        <td>
          <?php echo $this->translate($request->status);?>
        </td>
        <td>
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'requests', 'action' => 'edit', 'request_id' => $request->request_id),
            $this->translate("edit"),
            array('class' => 'smoothbox')) ?>
          |
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'badge', 'controller' => 'requests', 'action' => 'delete', 'request_id' => $request->request_id),
            $this->translate("delete"),
            array('class' => 'smoothbox')) ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

<br />

<?php else:?>
  <div class="tip">
    <span>
      <?php echo $this->translate("There are no requests given yet.") ?>
    </span>
  </div>
<?php endif; ?>
